<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>资方电子合同</title>
    <jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox col_33" >
                    <div class="label">客户姓名</div>
                    <div class="field">
                        <input type="text" id="cstNm" name="cstNm" class="ui-textbox"/>
                    </div>
                </div>
                <div class="fieldBox col_33" >
                    <div class="label">合同号</div>
                    <div class="field">
                        <input type="text" id="lsCntNo" name="lsCntNo" class="ui-textbox"/>
                    </div>
                </div>
                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round" onclick="searchBtn()">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round" onclick="clearBtn()">清空</span>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid" class="sq-grid"></div>
</div>

<script type="text/javascript">
    $(function () {
        initGrid();
    });

    function initGrid() {
        grid = $("#ligergrid").ligerGrid({
            url: '<%=path%>/asset/cont/resign/initList.do',
            parms:function(){
                return $("#searchBar").ligerForm().getData();
            },
            columns: [
                {display: '合同号', name: 'lsCntNo', enabledSort:true},
                {display: '客户姓名', name: 'cstNm',  enabledSort:true},
                {display: '第三方机构名称', name: 'fundRasInsNm', enabledSort:true},
                {display: '合同状态', name: 'assetContStsCd',enabledSort:true,
                    render: function (rowdata, rowindex, value) {
                        if (rowdata.assetContStsCd == "CREATED") {
                            return "未签署";
                        } else {
                            return "已签署";
                        }
                    }
                },
                {display: '资方签署状态', name: 'assetContStsNm',enabledSort:true},
                {display: '创建时间',name:'crtTm', enabledSort:true, render: dateRender},
                {display: '操作',
                    render:function (rowdata, rowindex, value, column) {
                        var h = "";
                        h+="<a href='javascript:void(0)' onclick='selectAssetContStatus("+rowdata.id+")'>状态查询</a>";
                        if (rowdata.assetContStsCd == "CREATED") {
                            h += "<a href='javascript:void(0)' onclick='resignPushCont(" + rowdata.id + ")'>重签推送</a>";
                        }
                        if (rowdata.assetContStsCd == "SIGNED") {
                            h += "<a href='javascript:void(0)' onclick='downloadCont(" + rowdata.id + ")'>下载</a>";
                        }
                        return h;
                    }
                }
            ],
            root:'rows',
            record:'total',
            hideLoadButton:false,
            width:'100%',
            height:'100%',
            heightDiff:-2,
            checkbox:false,//列表是否有选择框
            rownumbers:false//列表是否有行号
        });
    }

    function searchBtn(){
        grid.reload();
    }

    function clearBtn(){
        var form = new liger.get("searchBar");
        form.setData({
            cstNm: "",
            lsCntNo: ""
        });
    }

    function selectAssetContStatus(id) {
        if (!id) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
            return;
        }
        var selected = grid.getSelected();
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType:'json',
            data:{prjId:id},
            url: '<%=path%>/asset/cont/resign/selectAssetContStatus.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success:function(msg){
                wait_dialog.close();
                if(msg.success == 1) {
                    var assetContStsCd = msg.data;
                    var assetContStsNm = '未知状态';
                    if (assetContStsCd == 'UNAUDITED') {
                        assetContStsNm = '待审核';
                    } else if (assetContStsCd == 'AUDITED') {
                        assetContStsNm = '已审核';
                    } else if (assetContStsCd == 'SIGNED') {
                        assetContStsNm = '已签约';
                    } else if (assetContStsCd == 'CREATED') {
                        assetContStsNm = '已生成';
                    }
                    // grid.updateCell("assetContStsNm", assetContStsNm, grid.getSelected().__index);
                    selected.assetContStsCd = assetContStsCd;
                    selected.assetContStsNm = assetContStsNm;
                    grid.updateRow(selected.__index + 1, selected);
                    top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
                }else{
                    top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                }
            }
        });
    }

    function resignPushCont(id) {
        if (!id) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
            return;
        }

        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType:'json',
            data:{prjId:id},
            url: '<%=path%>/asset/cont/resign/resignPushCont.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success:function(msg){
                wait_dialog.close();
                if(msg.success == 1){
                    top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
                }else{
                    top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                }
            }
        });
    }

    function downloadCont(id) {
        if (!id) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
            return;
        }

        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType:'json',
            data:{prjId:id},
            url: '<%=path%>/asset/cont/resign/downloadCont.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success:function(msg){
                wait_dialog.close();
                if(msg.success == 1){
                    top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
                }else{
                    top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                }
            }
        });
    }

    function dateRender(rowdata, index, value) {
        var dateStr = '';
        if (null != value && '' != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

</script>
</body>
</html>